<?php

class galleryComponents extends sfComponents
{
    public function executeParent_tree()
    {
        $ids = Tree::getTreeIds(0);
        $ar = Tree::getTreeLng($ids, sfContext::getInstance()->getUser()->getCulture());
        $arOptions = array();
        foreach( $ar as $tree )
        {
            $arOptions[$tree->getId()] = $tree->getName();
        }
        $this->arOptions = $arOptions;
    }
    public function executeBacklink()
    {
        $gallery = gallery::getById((int)$this->getRequestParameter('id', 0));
        $this->tree = null;

        //debugvar($gallery);
        if( $gallery->getId() )
        {
            $c = new Criteria();
            //$c->add(TreePeer::USER_ID, $gallery->getUserId());
            $c->add(TreePeer::OBJ_TYPE, MyConstants::TYPE_TEXTMODULE);
            $c->add(TreePeer::OBJ_ID, $gallery->getId());
            $this->tree = TreePeer::doSelectOne($c);
            //debugvar($this->tree);
        }
    }

    public function executeText_layout_id()
    {
        $c = new Criteria();
        $this->arLayouts = TextLayoutPeer::doSelect($c);
    }

    public function executeGallery_list()
    {
        $this->arFiles = Files::getByObj(MyConstants::TYPE_GALLERY, $this->gallery->getId());
        $this->setFlash('returnCrop', $this->getModuleName().'/'.$this->getActionName().'?id='.$this->gallery->getId());
    }

    public function executePath()
    {
        if( $this->getRequestParameter('id') )
        {
            $this->page = GalleryPeer::retrieveByPk($this->getRequestParameter('id'));
            $c = new Criteria();
            $c->add(TreePeer::OBJ_ID, $this->page->getId());
            $obj = TreePeer::doSelectOne($c);
            $this->arParents = Tree::getBranchById($obj->getId(), $this->getUser()->getCulture());
        }
        //debugvar($this->path);
    }
}